package com.bxd.baodan.adapter;

import com.bxd.baodan.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MenuPopuoWindowAdapter extends BaseAdapter{
	private int[] iconsResources;
	private String[] titles;
	private LayoutInflater inflater;
	private Context context;
	
	public MenuPopuoWindowAdapter(int[] iconsResources, String[] titles,
			Context context) {
		super();
		this.iconsResources = iconsResources;
		this.titles = titles;
		this.context = context;
		inflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return titles.length;
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int position, View view, ViewGroup arg2) {
		// TODO Auto-generated method stub
		ViewHolder holder = null;
		if (view == null) {
			view = inflater.inflate(R.layout.menu_pop_window_item, null);
			holder = new ViewHolder();
			holder.text = (TextView) view.findViewById(R.id.menu_text);
			holder.icon = (ImageView) view.findViewById(R.id.menu_icon);
			view.setTag(holder);
		} else {
			holder = (ViewHolder) view.getTag();
		}
		
		if(iconsResources == null){
			holder.icon.setVisibility(View.GONE);
		}else{
			holder.icon.setVisibility(View.VISIBLE);
			holder.icon.setImageResource(iconsResources[position]);
		}
		holder.text.setText(titles[position]);
		
		return view;
	}
	
	class ViewHolder {
		private TextView text;
		private ImageView icon;
	}

}
